<include file="Public/min-header" />
<div class="wrapper">
	<include file="Public/breadcrumb"/>
	<style type="text/css">
		.navbar{margin-bottom: 0px;}
	</style>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	             <div class="box-header">
	           	   <nav class="navbar navbar-default">	     
				      <div class="collapse navbar-collapse">
	    				<div class="navbar-form form-inline">
				            <div class="form-group">
				            	<p class="text-success margin blod">店铺:</p>
				            </div>
				             <div class="form-group">
                                 <a class="btn btn-info" href="{:U('Store/store_list')}">店铺列表</a>&nbsp;&nbsp;&nbsp;&nbsp;                                            
                                 <a class="btn btn-default" href="{:U('Store/apply_list')}" >开店申请</a>&nbsp;&nbsp;&nbsp;&nbsp;                                            
                                 <!-- <a class="btn btn-default" href="{:U('Store/apply_class_list')}">经营类目申请</a>&nbsp;&nbsp;&nbsp;&nbsp; -->
				            </div>			          
				            <div class="form-group pull-right">
					            <a href="{:U('Store/store_add',array('is_own_shop'=>0))}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> 新增店铺</a>
				            </div>	
				          </div>
				       </div>
	    		 	</nav>	
	               	<nav class="navbar navbar-default">
				        <div class="collapse navbar-collapse">
				          <form class="navbar-form form-inline" action="{:U('Store/store_list')}" method="get">
							  <?php
							  if(session('fenbu_id')==0){
							  ?>
							  <div class="form-group">
							   <select name="fenbu_id" id="fenbu_id" class="input-sm" style="width:100px;">
								<foreach name="fenbu_list" item="v">
							   <option value="{$v['fenbu_id']}" <if condition="I('fenbu_id') eq $v['fenbu_id']">selected</if>>{$v['fenbu_name']}</option>
							   </foreach>
							   </select>
							  </div> 
							  <?php
							  }else{
							  	echo '<input type="hidden" name="fenbu_id" id="fenbu_id" value="'.session('fenbu_id').'" />';
							  }
							  ?>
				           	<div class="form-group">
				            	<label class="control-label" for="input-order-id">所属等级</label>
				            	 <select name="grade_id" class="form-control">
				            	 	  <option value="">选择等级</option>
                                      <foreach name="store_grade" item="item" key="k">
                                            <option value="{$k}" <if condition="$_GET['grade_id'] eq $k">selected</if>>{$item}</option>
                                      </foreach>
                                 </select>   
				            </div>
				           <div class="form-group">
				              	<input type="text" name="seller_name" class="form-control" placeholder="请输入店主名称">
				            </div>
				            <div class="form-group">
				            	<label class="control-label" for="input-order-id">店铺状态</label>
				            	 <select name="store_state" class="form-control">
				            	 	   <option value="">选择状态</option>
									   <option value="1" <?php if(I('store_state')=='1'){echo 'selected="selected"';};?>>开启</option>
				            	 	   <option value="0" <?php if(I('store_state')=='0'){echo 'selected="selected"';};?>>关闭</option>
                                       <option value="2" <?php if(I('store_state')=='2'){echo 'selected="selected"';};?>>已到期</option>
                                 </select>   
				            </div>
							  <div class="form-group">
								  <label class="control-label" for="input-order-id">是否快线</label>
								  <select name="fast_flag" class="form-control">
									  <option value="">请选择</option>
									  <option value="1" <?php if(I('fast_flag')=='1'){echo 'selected="selected"';};?>>是</option>
									  <option value="0" <?php if(I('fast_flag')=='0'){echo 'selected="selected"';};?>>否</option>
								  </select>
							  </div>
							  <div class="form-group">
								  <label class="control-label" for="input-order-id">是否免扫码</label>
								  <select name="open_san" class="form-control">
									  <option value="">请选择</option>
									  <option value="1" <?php if(I('open_san')=='1'){echo 'selected="selected"';};?>>是</option>
									  <option value="0" <?php if(I('open_san')=='0'){echo 'selected="selected"';};?>>否</option>
								  </select>
							  </div>
				           	<div class="form-group">
				            	<label class="control-label" for="input-order-id">店铺类别</label>
				            	 <select name="sc_id" class="form-control">
				            	 	  <option value="">选择类别</option>
                                      <volist name="store_class" id="item" key="k">
										  <?php
										  if(I('sc_id')==$k){
											  echo '<option value="'.$k.'" selected="selected">'.$item.'</option>';
										  }else{
											  echo '<option value="'.$k.'">'.$item.'</option>';
										  }
										  ?>
                                          
                                      </volist>                  
                                 </select>   
				            </div>
				            <div class="form-group">
				              	<input type="text" name="store_name" class="form-control" value="{:I('store_name')}" placeholder="请输店铺名称">
				            </div>
				            <button type="submit" class="btn btn-primary">查询</button>
<button type="button" class="btn btn-default pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>  
							  <button id="act_button" type="button" onclick="act_submit('fast');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量快线</button>
							  <button id="act_button" type="button" onclick="act_submit('san_code');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量开启免扫码</button>
							  <button id="act_button" type="button" onclick="act_submit('close_san_code');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量关闭免扫码</button>
				          </form>
				      	</div>
	    			</nav>
	             </div>
	             <div class="box-body">
	           	 <div class="row">
	            	<div class="col-sm-12">
		              <table id="list-table" class="table table-bordered table-striped dataTable">
		                 <thead>
		                   <tr role="row">
							   <td style="width: 1px;" class="text-center">
								   <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
							   </td>
							   <th>ID</th>
							   <th>店铺logo</th>
                               <th>店铺名称</th>
			                   <th>卖家账号</th>	
			                   <th>卖家账号ID</th>
							   <th>所属会员</th>
			                   <th>所属等级</th>
			                   <th>店铺类别</th>
							   <th>平台扣点</th>
			                   <th>状态</th>
							   <th>系统排序</th>
							   <th>对账排序</th>
<!--							   <th style="color:#ff9800;">区域溢价</th>-->
							   <th>快线标识</th>
		                  	   <th>首页推荐</th>
		                  	   <if condition="session('admin_id') eq 258 || session('admin_id') eq 284 || session('admin_id') eq 305">
							   <th>产品需审核</th>
							   </if>
							   <th>开启售后</th>
							   <th>商家号码状态</th>
							   <th>开启免扫码</th>
							   <th>显示联系方式</th>
							   <th>进驻日期</th>
							   <th>到期时间</th>
		                  	   <th style="text-align: center;">操作</th>
		                   </tr>
		                 </thead>
						<tbody>
                          <foreach name="list" item="vo" key="k" >
                             <tr role="row">
							 <td class="text-center">
								 <input type="checkbox" name="selected[]" value="{$vo['store_id']}">
							 </td>
							 <td>{$vo.store_id}</td>
							 <td><img width="50" height="50" src="{$vo.store_logo}"/></td>
                             <td>{$vo.store_name}</td>
							<td>{$vo.nickname}</td>
							<td>{$vo.seller_id}</td>
		                     <td>{$vo.seller_name}</td>
		                     <td>{$store_grade[$vo[grade_id]]}</td>
		                     <td>{$store_class[$vo[sc_id]]}</td>
							 <td style="color:#ff9800;">{$vo.koudian}%</td>
		                     <td><if condition="$vo[store_state] eq 1">开启<else/>关闭</if></td>
							 <td>
								 <input type="text" onchange="updateSort('store','store_id','{$vo.store_id}','store_sort',this)" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" maxlength="3" value="{$vo.store_sort}" class="input-sm" style="width: 50px;text-align: center;">
							 </td>
							 <td>
							 	 <input type="text" onchange="updateSort('store','store_id','{$vo.store_id}','dz_sort',this)" value="{$vo.dz_sort}" class="input-sm" style="width: 50px;text-align: center;">
							 </td>
<!--								 <td>-->
<!--									 <input type="text" onchange="updateSort2('store','store_id','{$vo.store_id}','store_yijia',this)"  maxlength="5" value="{$vo.store_yijia}" class="input-sm" style="width: 80px;text-align: center;border: #ff9800 solid 1px;">-->
<!--								 </td>-->

								 <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[fast_flag] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','fast_flag',this)"/></td>


								 <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[store_recommend] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','store_recommend',this)"/></td>
								 <if condition="session('admin_id') eq 258 || session('admin_id') eq 284 || session('admin_id') eq 305">
							  <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[goods_examine] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','goods_examine',this)"/></td>
							  </if>
							  <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[open_return] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','open_return',this)"/></td>
							  <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[phone_status] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','phone_status',this)"/></td>
								 <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[open_san] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','open_san',this)"/></td>
								 <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[mobile_staus] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('store','store_id','{$vo.store_id}','mobile_staus',this)"/></td>
							  <td>{$vo.store_time|date='Y-m-d',###}</td>
							  <td>{$vo.store_time_end|date='Y-m-d',###}</td>
							 
		                     <td class="text-center">

									<a class="btn btn-info" href="JavaScript:;" id="open_app" style="background:#3bcbf1;border: none;" data-store_id="{$vo.store_id}">开通app</a>

		                         <?php
                                	if(session('role_id')==192 || session('role_id')==20 || session('role_id')==1 || session('role_id')==191 ||  session('role_id')==235 ||  session('role_id')==15){
                                ?>
		                      	<a class="btn btn-info" href="/index.php/Seller/Admin/login/store_id/{$vo['store_id']}"  target="_blank" >管理</a>
		                     
		                      	<?php
                                	}
                                ?>

								 <?php
                                	if(session('role_id')!=15 ){
                                ?>
		                      	<a class="btn btn-info" href="{:U('Store/store_info_edit',array('store_id'=>$vo['store_id']))}">编辑</a>
		                      <!-- 	<a class="btn btn-info" href="{:U('Store/store_class_info',array('store_id'=>$vo['store_id']))}">经营类目</a> -->
							  <a class="btn btn-warning" href="JavaScript:;" id="blacklist" style="background:#000;border: none;" onclick="blacklist('{$vo.store_id}')" >黑名单</a>
							  <a class="btn btn-info" href="JavaScript:;" id="qingkong" style="background:#8bc34a;border: none;" rel="{$vo.store_id}">还原销量</a>
		                      	<a class="btn btn-danger" onclick="delfunc(this)" data-url="{:U('Store/store_del')}" data-id="{$vo.store_id}">删除</a>
		                      	<a href="javascript:;" onclick="fenbuKuncun('{$vo.store_id}')"   class="btn btn-primary" data-original-title="修改分部库存排序"><i class="fa fa-pencil"> 修改分部排序</i></a>
								 <a href="javascript:;" onclick="userfloating('{$vo.store_id}')"   class="btn btn-primary" data-original-title="店铺客户价格"><i class="fa fa-pencil"> 店铺客户价格</i></a>
								 <?php
                                	}
                                ?>
				     		</td>
		                   </tr>
		                  </foreach>
		                   </tbody>
		                 <tfoot>
		                 
		                 </tfoot>
		               </table>
	               </div>
	          </div>
              <div class="row">
              	    <div class="col-sm-6 text-left">
              	    	<button class="btn btn-default btn-sm checkbox-toggle"><i class="fa fa-square-o"></i></button>
              	    </div>
                    <div class="col-sm-6 text-right">{$page}</div>		
              </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
</div>
<script>

	$("#daochu").click(function(){
		var fenbu_id=$("#fenbu_id").val();
		var grade_id=$("#grade_id").val();
		var store_state=$("#store_state").val();
		var fast_flag=$("#fast_flag").val();
		var sc_id=$("#sc_id").val();
		var store_end_time=$("#store_end_time").val();
		var seller_name=$("#seller_name").val();
		
		location.href="/index.php/Admin/Store/export_store?fenbu_id="+fenbu_id+"&grade_id="+grade_id+"&store_end_time="+store_end_time+"&store_state="+store_state+"&fast_flag="+fast_flag+"&sc_id="+sc_id+"&seller_name="+seller_name;
	})
	function get_select_id_str() {
		if ($('input[name="selected\[\]"]:checked').length == 0)
			return false;
		var goods_arr = Array();
		$('input[name="selected\[\]"]:checked').each(function () {
			goods_arr.push($(this).val());
		});
		var id_str = goods_arr.join(',');
		return id_str
	}

			$(".box-body #qingkong").click(function(){
				if (!confirm('确定还原销量吗?'))
					return false;

				var loadIndex = layer.load(0);
				var store_id=$(this).attr('rel');
				$.post("/Admin/Store/store_list",{action:'qingkong',store_id:store_id},function(res){
					layer.close(loadIndex);
					layer.msg('销量还原成功！');
				})
			});
			
	// 修改指定表的排序字段 给商家使用的函数
	function updateSort2(table,id_name,id_value,field,obj)
	{
		var value = $(obj).val();
		if(field=="price" && (value=="" || value=="0")){
			alert("价格不能为：0 ！");
			return false;
		}
		$.ajax({
			url:"/index.php?m=Admin&c=Index&a=store_yijia&&store_id="+id_value+'&value='+value,
			success: function(data){
				layer.msg('更新成功', {icon: 1});
			}
		});
	}
	
		// 修改指定表的排序字段 给商家使用的函数

	function userfloating(store_id){

		layer.open({
			type: 2, //Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）,
			shadeClose: true, //点击遮罩关闭
			title:'店铺客户价格',
			skin: 'layui-layer-rim', //加上边框
			area: ['920px', '620px'], //宽高
			content:"/Admin/Store/store_userfloating?store_id="+store_id,//支持获取DOM元素
		});
	}
	function fenbuKuncun(store_id){
	    layer.open({
			  type: 2,
			  shadeClose: true, //点击遮罩关闭
			  title:'分部库存和排序',
			  skin: 'layui-layer-rim', //加上边框
			  area: ['920px', '620px'], //宽高
			  content: '{:U('Admin/Store/fenbuKuncun')}?store_id='+store_id
			});
	}

			//批量操作提交
			function act_submit(action) {
				//prompt层
				var ids = get_select_id_str();
				if (ids == false) {
					layer.alert('请勾选要操作的退货订单', {icon: 2});
					return;
				}
				console.log(ids);
				layer.confirm('确定操作吗？', {
					btn: ['确定','取消'] //按钮
				}, function(){
					$.post('/index.php/Admin/Store/store_list',{action:action,datas:ids},function(res){
						if(res!=''){
							layer.msg('操作成功！', {icon:6},function(){
								window.location.reload();
							});
						}else{
							layer.msg('操作！', {icon:5});
						}
					});
				});
			}


	function blacklist(store_id){

		layer.open({
			type: 2, //Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）,
			shadeClose: true, //点击遮罩关闭
			title:'黑名单',
			skin: 'layui-layer-rim', //加上边框
			area: ['920px', '620px'], //宽高
			content:"/Admin/Store/store_blacklist?store_id="+store_id,//支持获取DOM元素
		});
	}

	function empower(store_id){

		layer.open({
			type: 2, //Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）,
			title: '授权广西', //标题
			area: ['750px', '90%'],
			shade: 0,   //遮罩透明度
			shadeClose: true,
			scrollbar: true ,//屏蔽浏览器滚动条
			content:"/Admin/Store/empower?store_id="+store_id,//支持获取DOM元素
			end: function(){
				console.log(123123)
				window.location.reload();//关闭open打开的页面时，刷新父页面
			}
		});
	}
	$(".box-body #open_app").click(function (){
			const store_id = $(this).data('store_id');
			$.ajax({
				url: "{:U('Store/openApp')}",
				data: {store_id:store_id},
				type: 'post',
				dataType: "json",
				success: function(data){
					if(data.code){
						layer.msg(data.msg, {
							icon: 1,
							time: 1500
						});
					}else{
						layer.msg(data.msg, {
							icon: 2,
							time: 1500
						});
					}
				}
			});
		})
	function cancellation(store_id){
		layer.confirm('确定取消授权嘛？', {
			btn: ['确定','取消']
		}, function(){
			var index = layer.load();
			$.ajax({
				url: "{:U('Store/revoke')}",
				data: {store_id:store_id},
				type: 'post',
				dataType: "json",
				success: function (resp) {
					layer.close(index);
					//成功提示
					if (resp.status == 1) {
						layer.msg("取消成功", {
							icon: 1,
							time: 1500
						}, function () {
							location.reload();
						});
					} else {
						//失败提示
						layer.msg(resp.msg, {
							icon: 2,
							time: 2000
						});
					}
				}
			});
		}, function(index){

		});
	}
</script>

</body>
</html>   
